package com.group.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.group.pojo.TbRole;
import com.group.service.RoleService;

/**
 * 角色管理
 * @author caoyanan
 * @time 2017年10月11日下午8:28:25
 */
@Controller
@RequestMapping("/role")
public class RoleController {

	@Autowired 
	private RoleService roleService;
	
	@RequestMapping("/page.action")
	public String role() {
		return "admin/role";
	}
	
	@RequestMapping("/getAllRoles.action")
	@ResponseBody
	public List<TbRole> getAllRoles() {
		List<TbRole> list = roleService.getAllRoles();
		return list;
	}
	
	@RequestMapping("/save.action")
	@ResponseBody
	public Map<String, String> save(HttpServletRequest request, TbRole role) {
		Map<String, String> map = roleService.save(request, role);
		return map;
	}
	
	@RequestMapping("/batchDelete.action")
	@ResponseBody
	public Map<String, String> batchDelete(@RequestParam(value = "roleIds[]")String[] roleIds) {
		Map<String, String> map = roleService.batchDelete(roleIds);
		return map;
	}
	
	@RequestMapping("/getRoleById.action")
	@ResponseBody
	public TbRole getRoleById(String id) {
		TbRole role = roleService.getRoleById(id);
		return role;
	}
	
	@RequestMapping("/update.action")
	@ResponseBody
	public Map<String, String> update(TbRole role) {
		Map<String, String> map = roleService.update(role);
		return map;
	}
	
	@RequestMapping("/roleCheckRepect.action")
	@ResponseBody
	public String roleCheckRepect(TbRole role) {
		String isExist = roleService.roleCheckRepect(role);
		return isExist;
	}
}
